package com.ergwang.service.mail;

import com.ergwang.Model.Goods;
import com.ergwang.Model.Orders;
import com.ergwang.Model.mall.vo.GetOrderByStateVO;
import com.ergwang.Model.mall.vo.Orders_GoodsInfoVO;
import com.ergwang.dao.OrderMallDaoImpl;
import com.ergwang.dao.Order_MallDao;

import java.util.ArrayList;
import java.util.List;

/**
 * @author：ergwang
 * @Date: 2020/6/2
 * @Time: 14:19
 */
public class Order_MallServiceImpl implements Order_MallService {

    private Order_MallDao order_mallDao = new OrderMallDaoImpl();

    /**
     * 获取根据订单状态，获取加入购物车的订单
     * @param stateId 订单状态，购物车中的为0
     * @param nickname  下单人的用户名
     * @return 返回购物车数据列表
     */
    public List<GetOrderByStateVO> getOrderByState(String stateId, String nickname) {
        List<GetOrderByStateVO> ordersByState = new ArrayList<GetOrderByStateVO>();
        // 获取订单信息(不包括商品信息)
        List<Orders> orders_orders = order_mallDao.getOrders_OrderInfo(stateId,nickname);
        // 获取订单对应的商品信息
        for (Orders order:orders_orders) {
            Orders_GoodsInfoVO orders_goods = order_mallDao.getOrders_GoodsInfoVO(order.getGoodsId());
            orders_goods.setGoodsDetailId(order.getGoodsDetailId());
            orders_goods.setSpec(order.getSpec());
            ordersByState.add(new GetOrderByStateVO(order,orders_goods.getUnitPrice(),orders_goods));
        }
        return ordersByState;
    }

    public List<GetOrderByStateVO> getOrderByNickName(String nickname) {
        List<GetOrderByStateVO> ordersByState = new ArrayList<GetOrderByStateVO>();
        // 获取订单信息(不包括商品信息)
        List<Orders> orders_orders = order_mallDao.getOrderInfoByNickName(nickname);
        // 获取订单对应的商品信息
        for (Orders order:orders_orders) {
            Orders_GoodsInfoVO orders_goods = order_mallDao.getOrders_GoodsInfoVO(order.getGoodsId());
            orders_goods.setGoodsDetailId(order.getGoodsDetailId());
            orders_goods.setSpec(order.getSpec());
            ordersByState.add(new GetOrderByStateVO(order,orders_goods.getUnitPrice(),orders_goods));
        }
        return ordersByState;
    }
}
